/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * Description: Hmfs-tools constant
 */

#ifndef CONSTANT_H
#define CONSTANT_H

namespace OHOS {
namespace Hmfs {
enum class HmfsFileType {
    HMFS_FT_UNKNOWN,
    HMFS_FT_REG_FILE,
    HMFS_FT_DIR,
    HMFS_FT_CHRDEV,
    HMFS_FT_BLKDEV,
    HMFS_FT_FIFO,
    HMFS_FT_SOCK,
    HMFS_FT_SYMLINK,
    HMFS_FT_MAX,
    HMFS_FT_ORPHAN,
    HMFS_FT_XATTR,
    HMFS_FT_LAST_FILE_TYPE = HMFS_FT_XATTR,
};

enum class HmfsExtType : uint8_t {
    HMFS_INLINE_XATTR = 0x01,
    HMFS_INLINE_DATA = 0x02,
    HMFS_INLINE_DENTRY = 0x04,
    HMFS_DATA_EXIST = 0x08,
    HMFS_INLINE_DOTS = 0x10,
    HMFS_EXTRA_ATTR = 0x20,
    HMFS_PIN_FILE = 0x40,
    HMFS_COMPRESS_RELEASED = 0x80,
};

enum class ArgParseResult {
    OK = 0,
    FINISH,
    ERROR,
};

enum class CmdFunc {
    MKFS,
    FSCK,
    DUMP,
    RESIZE,
    SLOAD,
};

enum StopCpReason {
    CP_STOP_REASON_SHUTDOWN,
    CP_STOP_REASON_FAULT_INJECT,
    CP_STOP_REASON_META_PAGE,
    CP_STOP_REASON_WRITE_FAIL,
    CP_STOP_REASON_CORRUPTED_SUMMARY,
    CP_STOP_REASON_UPDATE_INODE,
    CP_STOP_REASON_FLUSH_FAIL,
    CP_STOP_REASON_MAX = 32,
};

enum CursegType {
    CURSEG_DATA_HOT = 0,
    CURSEG_DATA_WARM,
    CURSEG_DATA_COLD,
    CURSEG_NODE_HOT,
    CURSEG_NODE_WARM,
    CURSEG_NODE_COLD, 
    CURSEG_TYPE_MAX
};

constexpr const char *LPF_STRING = "lost+found";

constexpr uint32_t HMFS_FEATURE_ENCRYPT = 0x0001;
constexpr uint32_t HMFS_FEATURE_BLKZONED = 0x0002;
constexpr uint32_t HMFS_FEATURE_ATOMIC_WRITE = 0x0004;
constexpr uint32_t HMFS_FEATURE_EXTRA_ATTR = 0x0008;
constexpr uint32_t HMFS_FEATURE_PRJQUOTA = 0x0010;
constexpr uint32_t HMFS_FEATURE_INODE_CHKSUM = 0x0020;
constexpr uint32_t HMFS_FEATURE_FLEXIBLE_INLINE_XATTR = 0x0040;
constexpr uint32_t HMFS_FEATURE_QUOTA_INO = 0x0080;
constexpr uint32_t HMFS_FEATURE_INODE_CRTIME = 0x0100;
constexpr uint32_t HMFS_FEATURE_LOST_FOUND = 0x0200;
constexpr uint32_t HMFS_FEATURE_VERITY = 0x0400;
constexpr uint32_t HMFS_FEATURE_SB_CHKSUM = 0x0800;
constexpr uint32_t HMFS_FEATURE_CASEFOLD = 0x1000;
constexpr uint32_t HMFS_FEATURE_COMPRESSION = 0x2000;
constexpr uint32_t HMFS_FEATURE_RO = 0x4000;

constexpr uint32_t DEVICE_PATH_MAX_LEN = 64;
constexpr uint32_t MAX_DEVICE_COUNT = 8;
constexpr uint32_t HMFS_META_SEGMENTS = 6;
constexpr uint32_t HMFS_META_SEGMENTS_RO = 2;
constexpr uint32_t VOLUME_NAME_MAX_LEN = 512;
constexpr uint8_t HMFS_ENC_UTF8_12_1 = 1;
constexpr uint8_t HMFS_MIN_SEGMENT_COUNT = 9;
constexpr uint32_t HMFS_BLOCK_SIZE = 4096;
constexpr uint32_t BLOCKS_PER_SEGMENT = 512;
constexpr uint64_t HMFS_MAX_DISK_SIZE = 16ULL * 1024 * 1024 * 1024 * 1024;
constexpr uint32_t HMFS_MAX_SEGMENT = (16 * 1024 * 1024) / 2;
constexpr uint32_t HMFS_SUPER_BLOCK_COUNT = 2;
constexpr uint32_t HMFS_MAGIC_NUMBER = 0xF2F52010;
constexpr uint32_t HMFS_SUPER_BLOCK_OFFSET = 1024;
constexpr uint32_t SB_CHECKSUM_OFFSET = 3068;
constexpr uint32_t BITS_PER_BYTE = 8;
constexpr uint32_t PERCENT_TIMES = 100;
constexpr uint32_t EXTENSION_LEN_MAX = 8;
constexpr uint32_t EXTENSION_COUNT_MAX = 64;
constexpr uint32_t DEFAULT_SECTOR_SIZE = 512;
constexpr uint32_t DEFAULT_SECTORS_PER_BLOCK = 8;
constexpr uint32_t SECTOR_SIZE_SHIFT = 9;
constexpr uint32_t HMFS_MIN_LOG_SECTOR_SIZE = 9;
constexpr uint32_t HMFS_MAX_LOG_SECTOR_SIZE = 12;
constexpr uint32_t DEFAULT_DIR_LEVEL = 0;
constexpr uint32_t HMFS_MAX_ERRORS = 16;
constexpr uint32_t HMFS_MAX_ACTIVE_LOGS = 16;
constexpr uint32_t HMFS_MAX_ACTIVE_NODE_LOGS = 8;
constexpr uint32_t HMFS_MAX_ACTIVE_DATA_LOGS = 8;
constexpr uint32_t SUPER_BLOCK_RESERVED_SIZE = 258;
constexpr uint32_t CURSEG_DATA_TYPE_COUNT = 3;
constexpr uint32_t CURSEG_NODE_TYPE_COUNT = 3;
constexpr uint32_t SIT_VBLOCK_MAP_SIZE = 64;
constexpr uint32_t HMFS_NAT_COUNT = 2;
constexpr uint32_t DEFAULT_NAT_ENTRY_RATIO = 20;
constexpr uint32_t HMFS_SIT_COUNT = 2;
constexpr uint32_t HMFS_CP_COUNT = 2;

#ifdef HMFS_TOOLS_ARM64
constexpr uint32_t CP_FLAG_RESIZEFS         = 0x00008000;
constexpr uint32_t CP_FLAG_DISABLED         = 0x00004000;
constexpr uint32_t CP_FLAG_QUOTA_NEED_FSCK  = 0x00001000;
constexpr uint32_t CP_FLAG_LARGE_NAT_BITMAP = 0x00002000;
constexpr uint32_t CP_FLAG_NOCRC_RECOVERY   = 0x00000200;
constexpr uint32_t CP_FLAG_TRIMMED          = 0x00000100;
constexpr uint32_t CP_FLAG_CRC_RECOVERY     = 0x00000040;
constexpr uint32_t CP_FLAG_FASTBOOT         = 0x00000020;
constexpr uint32_t CP_FLAG_FSCK             = 0x00000010;
constexpr uint32_t CP_FLAG_ERROR            = 0x00000008;
constexpr uint32_t CP_FLAG_COMPACT_SUM      = 0x00000004;
constexpr uint32_t CP_FLAG_ORPHAN_PRESENT   = 0x00000002;
constexpr uint32_t CP_FLAG_UMOUNT           = 0x00000001;
constexpr uint32_t CP_FLAG_APPEND_SIT       = 0x00000400;
constexpr uint32_t CP_FLAG_APPEND_NAT       = 0x00000800;
#else
constexpr uint32_t CP_FLAG_RESIZEFS         = 0x00004000;
constexpr uint32_t CP_FLAG_DISABLED         = 0x00001000;
constexpr uint32_t CP_FLAG_QUOTA_NEED_FSCK  = 0x00000800;
constexpr uint32_t CP_FLAG_LARGE_NAT_BITMAP = 0x00000400;
constexpr uint32_t CP_FLAG_NOCRC_RECOVERY   = 0x00000200;
constexpr uint32_t CP_FLAG_TRIMMED          = 0x00000100;
constexpr uint32_t CP_FLAG_NAT_BITS         = 0x00000080;
constexpr uint32_t CP_FLAG_CRC_RECOVERY     = 0x00000040;
constexpr uint32_t CP_FLAG_FASTBOOT         = 0x00000020;
constexpr uint32_t CP_FLAG_FSCK             = 0x00000010;
constexpr uint32_t CP_FLAG_ERROR            = 0x00000008;
constexpr uint32_t CP_FLAG_COMPACT_SUM      = 0x00000004;
constexpr uint32_t CP_FLAG_ORPHAN_PRESENT   = 0x00000002;
constexpr uint32_t CP_FLAG_UMOUNT           = 0x00000001;
#endif
constexpr uint32_t RESERVED_BYTES = 2;
constexpr uint32_t ENTRY_COUNT_IN_SUM = 512;
constexpr uint32_t NAT_MIN_BITMAP_SIZE = 64;
constexpr uint32_t SIT_USER_BLOCK_COUNT_SHIFT = 10;

constexpr uint32_t HMFS_NAME_LEN = 255;
constexpr uint32_t ADDR_COUNT_PER_INODE = 923;

constexpr uint32_t DEF_ADDRS_PER_BLOCK = 1018;
constexpr uint32_t NIDS_PER_BLOCK = 1018;

constexpr uint32_t DENTRY_COUNT_IN_BLOCK = 214;
constexpr uint32_t HMFS_SLOT_LEN = 8; 

constexpr uint32_t NULL_SEGNO = ~0;
constexpr uint32_t LINUX_S_IFMT = 00170000;
constexpr uint32_t LINUX_S_IFREG = 00170000;
constexpr uint32_t HMFS_COMPR_FL = 0x00000004;
constexpr int32_t DEFAULT_INLINE_XATTR_ADDRS = 0x00000004;
constexpr uint32_t FS_IMMUTABLE_FL = 0x00000010;
constexpr int32_t DEF_ADDRS_PER_INODE = 923;
constexpr uint8_t CRC_SHIFT = 32;

constexpr uint32_t HMFS_BLKSIZE_BITS = 12;
constexpr uint32_t BLOCKS_TO_MB_SHIFT = 8;
constexpr uint32_t MB_SHIFT = 20;
constexpr uint32_t VERSION_TOTAL_LEN = 256;
constexpr uint32_t VERSION_TIMESTAMP_LEN = 4;

constexpr uint32_t NODE_ID_COUNT = 5;
constexpr uint32_t UUID_SIZE = 16;
constexpr uint32_t ENCRYPTION_SALT_SIZE = 16;
constexpr uint32_t EXTRA_INFO_HEADER_SIZE = 2;
constexpr uint32_t EXTRA_INFO_FOOTER_SIZE = 8;

constexpr uint32_t PERCENTAGE_DIVISOR = 100;
constexpr int32_t HMFS_HASH_COL_BIT_SHIFT = 63;
constexpr uint8_t CANDIDATE_ADDNUM = 6;

constexpr uint32_t HMFS_ZONED_NONE = 0;
constexpr uint32_t HMFS_ZONED_HA = 1;
constexpr uint32_t HMFS_ZONED_HM = 2;

constexpr uint32_t HMFS_REPORT_ZONES_BUFSZ = 524288;

constexpr long MIN_NUM_CACHE_ENTRY = 1024;
constexpr uint8_t NUM_DIVISOR = 2;
constexpr uint8_t BUF_SHIFT = 5;
constexpr uint8_t BUF_INDEX0 = 0;
constexpr uint8_t BUF_INDEX1 = 1;
constexpr uint8_t BUF_INDEX2 = 2;
constexpr uint8_t BUF_INDEX3 = 3;

constexpr uint8_t CRC_BITS = 8;

constexpr double CASE1_CANDIDATE = 10;
constexpr double CASE1_END = 95;
constexpr double CASE1_DIFF = 5;

constexpr double CASE2_CANDIDATE = 0.01;
constexpr double CASE2_END = 10;
constexpr double CASE2_DIFF = 0.01;

constexpr int32_t NUM_COEFFICIENT = 4;

constexpr uint8_t POS_STEP = 16;

constexpr uint32_t SEED1 = 0x67452301;
constexpr uint32_t SEED2 = 0xefcdab89;
constexpr uint32_t SEED3 = 0x98badcfe;
constexpr uint32_t SEED4 = 0x10325476;

constexpr uint8_t NUM_SHIFT = 3;
constexpr uint8_t NUM_MASK = 0x07;
constexpr uint8_t NUM_OFFSET = 4;

constexpr uint8_t VAR_NUM = 2;
constexpr uint8_t VALUE_SHIFT = 8;

constexpr uint8_t HASH_MAX_LEN = 4;
constexpr uint8_t PAD_SHIFT = 16;
constexpr uint8_t DENTRIES_MAX_LEN = 2;

constexpr uint16_t SEGMENT_MAX_COUNT = 256;
constexpr uint8_t CANDIDATE_COEFFICIENT = 2;
constexpr uint64_t INODE_FILESIZE = 6 * 1024;

constexpr uint32_t CURRENT_COLD_DATA_ZONE_SHIFT = 2;

constexpr uint32_t CHECKPOINT_ONE = 1;
constexpr uint32_t CHECKPOINT_TWO = 2;
constexpr uint32_t BITS_IN_BYTE_ARRAY_SIZE = 256;
constexpr uint32_t ZONED_RESV_SIZE = 4;
constexpr uint32_t ZONED_RESERVED_SIZE = 24;
constexpr uint32_t CP_CHKSUM_OFFSET = 4092;
} // namespace Hmfs
} // namespace OHOS
#endif